/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("gbcp_wenju",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.MyTable.IServices;
using Microsoft.AspNetCore.Authorization;
using VOL.Core.Filters;
using VOL.Core.Utilities;
using System.Collections;
using VOL.Core.DBManager;
using System.Linq;

namespace VOL.MyTable.Controllers
{
    public partial class gbcp_wenjuController
    {
        private readonly Igbcp_wenjuService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public gbcp_wenjuController(
            Igbcp_wenjuService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }
        [HttpPost, Route("GetPageData"), AllowAnonymous]
        [ApiActionPermission()]//权限重写，在控制器中增加
        public override ActionResult GetPageData([FromBody] PageDataOptions loadData)
        {
            return base.GetPageData(loadData);
        }
        [HttpPost, Route("Update"), AllowAnonymous]
        [ApiActionPermission()]//权限重写，在控制器中增加
        public override ActionResult Update([FromBody] SaveModel saveModel)
        {
            return base.Update(saveModel);
        }
        [HttpPost, Route("Add"), AllowAnonymous]
        [ApiActionPermission()]//权限重写，在控制器中增加
        public override ActionResult Add([FromBody] SaveModel saveModel)
        {
            for (int i = 0; i <= saveModel.MainData.Keys.Count - 1; i++)//轮询修改字典的key/value
            {
                if (saveModel.MainData.ContainsKey("ipaddress"))
                {
                    saveModel.MainData["ipaddress"] = CustomHelper.GetClientUserIp();
                }
            }
            return base.Add(saveModel);
        }
        [HttpPost, Route("get_data_all_cpren"),AllowAnonymous]//获取所有被测评人
        public dynamic get_data_all_cpren()
        {
            Hashtable rtn_hst = new Hashtable();
            var all_ren = DBServerProvider.DbContext.Set<gbcp_cpmd>().ToList();
            var pjz_ren = DBServerProvider.DbContext.Set<gbcp_pjz>().ToList();
            var all_dep = all_ren.Select(s => s.yjjg).Distinct();
            rtn_hst.Add("all_ren", all_ren);
            rtn_hst.Add("pjz_ren", pjz_ren);
            rtn_hst.Add("all_dep", all_dep);
            return rtn_hst;
        }
    }
}
